﻿using System.Collections.Generic;
using System.Data;
using BrandonHaynes.Data;

namespace BrandonHaynes.Providers.AmazonS3.Data
	{
	/// <summary>
	/// Extension methods for the CompositeDataReader object, used to (hopefully) increase readability.
	/// </summary>
	static class CompositeIDataReaderExtensions
		{
		/// <summary>
		/// Returns a composite IDataReader that is the union of two provided IDataReaders
		/// </summary>
		public static IDataReader Union(this IDataReader firstReader, IDataReader reader)
			{ return new CompositeDataReader(firstReader, reader); }

		/// <summary>
		/// Creates a composite IDataReaders that is the union of a given reader and an enumeration of additional objects
		/// </summary>
		public static IDataReader Union<T>(this IDataReader reader, IEnumerable<T> elements)
			{ return Union(reader, new ReflectedDataReaderAdapter(elements)); }

		/// <summary>
		/// Returns a composite IDataReader that is the union of a given reader and an arbitrary object
		/// </summary>
		public static IDataReader Union(this IDataReader reader, object element)
			{ return Union(reader, element.ToEnumerable()); }

		/// <summary>
		/// Converts an enumeration of arbitrary objects into an IDataReader-implementing object
		/// </summary>
		public static IDataReader ToReader<T>(this IEnumerable<T> elements)
			{ return new ReflectedDataReaderAdapter(elements); }

		/// <summary>
		/// Converts an object into an IDataReader-implementing object
		/// </summary>
		public static IDataReader ToReader(this object element)
			{ return element.ToEnumerable().ToReader(); }
		}
	}
